package com.jxnu.duewang.zmly.zouZhen.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.jxnu.duewang.zmly.R;

import org.greenrobot.eventbus.EventBus;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Project Zmly
 * Author Duewang
 * Time 2016/12/10 0010
 */

public class DefineDialog extends Dialog {

    private Context mContext;

    @OnClick({R.id.dialog_cancel,R.id.dialog_min,R.id.dialog_comfire})
    public void onClick(TextView textView){
        switch (textView.getId()) {
            case R.id.dialog_cancel:
                dismiss();
                break;
            case R.id.dialog_min:
                dismiss();
                EventBus.getDefault().post(R.id.dialog_min);
                break;
            case R.id.dialog_comfire:
                EventBus.getDefault().post(R.id.dialog_comfire);
                break;
        }
    }

    public DefineDialog(Context context) {
        super(context);
        mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        init();
    }

    private void init(){
        View view = LayoutInflater.from(mContext).inflate(R.layout.define_dialog, null);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(view);
        ButterKnife.bind(this);
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams params = dialogWindow.getAttributes();
        DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
        params.width=( int )( displayMetrics.widthPixels * 0.8 );
        dialogWindow.setAttributes(params);
    }

}
